<template>
    <van-nav-bar 
    :title="title" 
    :left-arrow="showLeft" 
    @click-left="handler" 
    @click-right="onClickRight" 
    :right-text="right" />
</template>

<script setup>
import { defineProps, defineEmits, toRefs } from 'vue';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
let store = useStore();
let router = useRouter();
let props = defineProps({
    back: {
        type: Boolean,
        default: true
    },
    title: {
        type: String,
        default: '标题'
    },
    right: {
        type: String,
        default: ''
    },
    showLeft: {
        type: Boolean,
        default: true
    }
});

let emits = defineEmits(['onClickRight']);

let onClickRight = () => {
    emits('onClickRight');
};

let { title, right, back } = toRefs(props);

const handler = () => {
    store.state.routerType = 'push';
    router.go(-1);
};
</script>

<style lang="scss" scoped>
.title {
    height: 0.64rem;
    line-height: 0.64rem;
    text-align: center;
    background-color: #fff;
    position: sticky;
    top: 0;
    box-sizing: border-box;
    // display: flex;
    // justify-content: space-between;
    padding: 0 0.2rem;
    .back {
        position: absolute;
        left: 0.2rem;
        top: 0;
        i {
            font-size: 0.2rem;
        }
    }
    p {
        font-size: 0.16rem;
        width: 100%;
        text-align: center;
    }
    .right {
        position: absolute;
        right: 0.2rem;
        top: 0;
        font-size: 0.14rem;
        color: #333;
    }
}
</style>
